package com.cjw.service.impl.operationAnalysis;

import com.cjw.mapper.database.OperationLogMapper;
import com.cjw.pojo.dto.operationAnalysis.AccessDTO;
import com.cjw.pojo.dto.operationAnalysis.BarDTO;
import com.cjw.pojo.entity.database.OperationLog;
import com.cjw.service.operationAnalysis.ResourceAccessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.ArrayList;
import java.util.List;

/**
 * @author : cjw
 * @date: : 2022/3/17 21:43
 * @description : ResourceAccessService
 */
@Service
public class ResourceAccessServiceImpl implements ResourceAccessService {
    @Autowired
    private OperationLogMapper operationLogMapper;

    @Override
    public List<BarDTO> getRequestBar() {
        ArrayList<BarDTO> barDTOs = new ArrayList<>();
        String[] requests = new String[]{"查询","修改","添加","删除"};
        for (String request : requests) {
            Example example = new Example(OperationLog.class);
            Example.Criteria criteria = example.createCriteria();
            criteria.andEqualTo("description", request);
            BarDTO barDTO = new BarDTO();
            barDTO.setName(request);
            barDTO.setValue(operationLogMapper.selectCountByExample(example));
            barDTOs.add(barDTO);
        }
        return barDTOs;
    }

    @Override
    public List<AccessDTO> access() {
        return operationLogMapper.access();
    }
}
